import request from "@/utils/request";
import { CardReaderDeviceEditForm } from "./types";

/**
 * 卡读卡器设备列表
 * @param data
 */
export function QueryCardReaderDeviceList(data: any) {
  return request({
    url: "/api/v1/sysuser/cardReaderDevice/page",
    method: "get",
    params: data,
  });
}

/**
 * 卡读卡器设备详情
 * @param id
 */
export function QueryCardReaderDeviceDetail(id: number) {
  return request({
    url: `/api/v1/sysuser/cardReaderDevice/${id}/form`,
    method: "get",
  });
}

/**
 * 卡读卡器设备新增
 * @param data
 */
export function AddCardReaderDevice(data: CardReaderDeviceEditForm) {
  return request({
    url: "/api/v1/sysuser/cardReaderDevice/create",
    method: "post",
    data,
  });
}

/**
 * 卡读卡器设备修改
 * @param data
 */
export function UpdateCardReaderDevice(data: CardReaderDeviceEditForm) {
  return request({
    url: `/api/v1/sysuser/cardReaderDevice/${data.id}`,
    method: "put",
    data,
  });
}

/**
 * 卡读卡器设备删除
 * @param ids
 */
export function DeleteCardReaderDevice(ids: number) {
  return request({
    url: `/api/v1/sysuser/cardReaderDevice/${ids}`,
    method: "delete",
  });
}

/**
 * 卡读卡器设备启用
 * @param id
 */
export function EnableCardReaderDevice(id: number) {
  return request({
    url: `/api/v1/sysuser/cardReaderDevice/enable/${id}`,
    method: "put",
  });
}

/**
 * 卡读卡器设备禁用
 * @param id
 */
export function DisableCardReaderDevice(id: number, disableReason: string) {
  return request({
    url: `/api/v1/sysuser/cardReaderDevice/disable/${id}`,
    method: "put",
    params: {
      disableReason,
    },
  });
}

/**
 * 卡读卡器设备审核
 * @param data
 */
export function AuditCardReaderDevice(id: number) {
  return request({
    url: `/api/v1/sysuser/cardReaderDevice/audit/${id}`,
    method: "put",
  });
}

/*
 * App考勤授权分页
 */
export function QueryAppCheckinAuthList(data: any) {
   let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/AppCheckinAuth/page`;
      break;
    case "Corp":
      url = `/api/v1/corp/AppCheckinAuth/page`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/AppCheckinAuth/page`;
      break;
    case "Manager":
      url = `/api/v1/manager/AppCheckinAuth/page`;
      break;
    case "Commander":
      url = `/api/v1/commander/AppCheckinAuth/page`;
      break;
    default:
      url = `/api/v1/sysuser/AppCheckinAuth/page`;
      break;
  }
  return request({
    //url: "/api/v1/sysuser/AppCheckinAuth/page",
    url:url,
    method: "get",
    params: data,
  });
}

/**
 * 获取App考勤授权
 */
export function GetAppCheckinAuthForm(id: number) {
  return request({
    url: "/api/v1/sysuser/AppCheckinAuth/" + id + "/form",
    method: "get",
  });
}

/**
 * 新增App考勤授权
 */
export function CreateAppCheckinAuth(data: AppCheckinAuthEditForm) {
  return request({
    url: "/api/v1/sysuser/AppCheckinAuth/create",
    method: "post",
    data: data,
  });
}
/**
 * 编辑App考勤授权
 */
export function UpdateAppCheckinAuth(data: AppCheckinAuthEditForm) {
  return request({
    url: "/api/v1/sysuser/AppCheckinAuth/" + data.id,
    method: "put",
    data: data,
  });
}

/**
 * 删除App考勤授权
 */
export function DeleteAppCheckinAuth(id: number) {
  return request({
    url: "/api/v1/sysuser/AppCheckinAuth/" + id,
    method: "delete",
  });
}

/**
 * 启用App考勤授权
 */
export function EnableAppCheckinAuth(id: number) {
  return request({
    url: "/api/v1/sysuser/AppCheckinAuth/enable/" + id,
    method: "put",
  });
}

/**
 * 禁用App考勤授权
 */
export function DisableAppCheckinAuth(id: number) {
  return request({
    url: "/api/v1/sysuser/AppCheckinAuth/disable/" + id,
    method: "put",
  });
}
